<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Events\AfterSheet;

class CustomerBillExport implements FromCollection, WithHeadings, WithColumnWidths, WithEvents
{
    protected $data;
    protected $head;

    public function __construct(Collection $data, $head)
    {
        $this->data = $data;
        $this->head = $head;
    }

    public function collection()
    {
        return $this->data;
    }

    public function headings(): array
    {
        return $this->head;

    }

    public function columnWidths(): array
    {
        // 设置每列的宽度
        return [

            // 根据你的需求设置其他列的宽度
        ];
    }

    public function registerEvents(): array
    {
        return [
            AfterSheet::class => function(AfterSheet $event) {
                $event->sheet->getDelegate()->freezePane('A2');
            },
        ];
    }

}